<?php 
// namespace app\Chat;
class Template{
	// private $accesstoken; //公众号access token
	// private $openid; //家长openid
	// private $template;  //消息模板
	private $all;
	public function __construct($all) {
		// $this->accesstoken = $ast;
		// $this->openid = $opd;
		// $this->template = $tpl;
		$this->all = $all;
	}
	public function send() {
		dd($this->all);
		die;
		$arr = $this->all;
		$access_token = '8_kEp2rpl0fQ-Qtr6VtXYED8ZBEEjS_aTgF07W0ViraZ0R_YULTntiTKQpl4FgwBQbVga10f4rS3P4WT7QiYToVweyF-i_6Fji5I8GJAL-rTmdMrxX_fxJljUZde6xC-i14w1vvCoyahv20jNbBPDeAAAIWK';
		$url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token='. $access_token;//access_token改成你的有效值
		$data = array(
		    'first' => array(
		        'value' => $arr['student_name'],
		        'color' => '#FF0000'
		    ),
		    'keyword1' => array(
		        'value' => $arr['class_table'],
		        'color' => '#FF0000'
		    ),
		    'keyword2' => array(
		        'value' => $arr['class'],
		        'color' => '#FF0000'
		    ),
		    'keyword3' => array(
		        'value' => $arr['teacher'],
		        'color' => '#FF0000'
		    ),
		    
		    'keyword4' => array(
		        'value' => 1,
		        'color' => '#FF0000'
		    ),
		    'keyword5' => array(
		        'value' => $arr['one_money'],
		        'color' => '#FF0000'
		    ),
		    'keyword6' => array(
		        'value' => $arr['tot_time'],
		        'color' => '#FF0000'
		    ),
		    'keyword7' => array(
		        'value' => $arr['tot_money'],
		        'color' => '#FF0000'
		    ),
		    'keyword8' => array(
		        'value' => $arr['s_hours'],
		        'color' => '#FF0000'
		    ),
		    'keyword9' => array(
		        'value' => $arr['s_money'],
		        'color' => '#FF0000'
		    ),
		    'remark' => array(
		        'value' => '',
		        'color' => '#FF0000'
		    )
		);

		$template_msg=array('touser'=>$all['openid'],'template_id'=>'sabnF_bqTLD0ht9vjFEI_RXG-qcYoXLCptxNqGrmb9A','topcolor'=>'#FF0000','data'=>$data);
		$curl = curl_init($url);
		$header = array();
		$header[] = 'Content-Type: application/x-www-form-urlencoded';
		curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
		// 不输出header头信息
		curl_setopt($curl, CURLOPT_HEADER, 0);
		// 伪装浏览器
		curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36');
		// 保存到字符串而不是输出
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		// post数据
		curl_setopt($curl, CURLOPT_POST, 1);
		// 请求数据
		curl_setopt($curl,CURLOPT_POSTFIELDS,json_encode($template_msg));
		$response = curl_exec($curl);
		curl_close($curl);
		echo $response;
				
	}

}

 ?>